/**
 *  @author Cornelius Huang
 *  directive uitl here
 */
app.directive('setCount', [function() {
	return {
		restrict: 'AE',
		templateUrl: './views/setCount.html',
		scope: {
			slModel: '=?'
		},
		controller: ['$scope', function($scope) {
			$scope.slModel = 1;
			
			$scope.plus = function() {
				$scope.slModel++;
			}
			
			$scope.minus = function() {
				if($scope.slModel !== 1) {
					$scope.slModel--;
				}
			}
			
			$scope.preventInvalid = function() {
				if(isNaN($scope.slModel)) {
					$scope.slModel = 1;
				}
				if($scope.slModel < 1) {
					$scope.slModel = 1;
				}
			}
		}]
	}
}]);

app.directive('assCapa', function() {
	return {
		restrict: 'AE',
		template: '<select ng-options="capa.capName for capa in capaes track by capa.capId" ng-model="slModel" class="slt-fix"></select>',
		scope: {
			slModel: '=?',
			capa: '=?'
		},
		controller: ['$scope', 'demandService', function($scope, demandService) {
			var $ctrl = this;
			
			$ctrl.$onInit = function() {
				demandService.getSelects().then(function(sdac) {
					$scope.capaes = sdac.drmsCapability;
					console.log($scope.capaes);
				});
			}
			$scope.$watch('capa', function(newValue, oldValue) {
				if($scope.capaes !== undefined) {
					$scope.capaes.forEach(function(capa) {
						if(capa.capName === $scope.capa) {
							$scope.slModel = capa;
						}
					})
				}
			})
		}]
	}
});